<?php
namespace app\admin\actions\tagLib;
use Throwable;
use think\template\TagLib;
//require "extend/lib/lessc/lessc.inc.php";

error_reporting(0);

class load extends TagLib{
	//定义清缓存的引入标签，<load:css  src=""> ，<load:js  src="">
    protected $tags = array(
        'css' => array('attr' => 'src','close' =>0),
        'js' => array('attr' => 'src','close' =>0),
 	);
 	
 	public function tagCss ($attr,$content){
		$src = $this->getPath( $attr['src'] );
		return "<link  rel='stylesheet' href='$src'/>";
    }
	
    public function tagJs ($attr,$content){
       	$src = $this->getPath( $attr['src'] );
        return "<script src='$src'></script>";
    }
	
	//获取路径
	private function getPath($src){
		if (! function_exists('root_path')) {
		    function root_path($path = ''){
		        return env('root_path').($path ? ltrim($path, DIRECTORY_SEPARATOR) : 
		        ltrim($path, DIRECTORY_SEPARATOR));
		    }
		}
        $path = str_replace("//","/",(public_path().$src));
		$md5File = '1.0';
		try {
			$md5File = md5_file( $path );
		} catch (Throwable $th) {
			//throw $th;
		}
        return strstr($path,"?") ? $src : $src.'?ver='. $md5File;
	}
 
}
?>